package com.gxa.insurance.controller;

import com.gxa.insurance.pojo.AutomobileBrand;
import com.gxa.insurance.pojo.Model;
import com.gxa.insurance.pojo.Series;
import com.gxa.insurance.service.AutomobileBrandService;
import com.gxa.insurance.util.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author wang li sha
 * @date 2022-06-06 17:58
 */
@Api(value = "汽车品牌automobileBrand相关的api接口")
@RestController
@RequestMapping("/automobileBrand")
@CrossOrigin
public class AutomobileBrandController {
    @Autowired
    AutomobileBrandService automobileBrandService;

    @ApiOperation("修改汽车品牌的方法")
    @PostMapping("/update")
    public Map update(@RequestBody AutomobileBrand automobileBrand) throws Exception {
        Integer update = automobileBrandService.update(automobileBrand);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(update);
        return jsonResult.getMap();
    }


    @ApiOperation("添加汽车品牌的方法")
    @PostMapping("/insert")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "用户token", paramType = "header")
    })
    public Map insert(@RequestBody AutomobileBrand automobileBrand, @RequestHeader(value = "token", required = false) String token) throws Exception {
        Integer insert = automobileBrandService.insert(automobileBrand);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(insert);
        return jsonResult.getMap();
    }

    @ApiOperation("根据id查询汽车品牌的方法")
    @PostMapping("/selectById")
    public Map selectById(@RequestParam("id") Integer id) throws Exception {
        AutomobileBrand automobileBrand = automobileBrandService.selectById(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(automobileBrand);
        return jsonResult.getMap();
    }

    @ApiOperation("查询所有汽车品牌的方法")
    @PostMapping("/selectAll")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "用户token", paramType = "header")
    })
    public Map selectAll(@RequestHeader(value = "token", required = false) String token) throws Exception {
        List<String> automobileBrands = automobileBrandService.selectAll();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(automobileBrands);
        return jsonResult.getMap();
    }

    @ApiOperation(value = "获取品牌系列", produces = "query")
    @ApiImplicitParam(name = "name", value = "品牌名", paramType = "query")
    @PostMapping("/getSeries")
    public Map getSeries(String name) throws Exception {
        List<Series> series = automobileBrandService.getSeries(name);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(series);
        return jsonResult.getMap();
    }

    @ApiOperation(value = "获取品牌系列型号", produces = "query")
    @ApiImplicitParam(name = "name", value = "系列名", paramType = "query")
    @PostMapping("/getModel")
    public Map getModel(String name) throws Exception {
        List<Model> model = automobileBrandService.getModel(name);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(model);
        return jsonResult.getMap();
    }

}
